/**
 * Created by smp on 2017/3/16.
 */

//表单提交
$('#dictionaryTypeSave').on('click',function () {
    layer.confirm('是否确定保存？', {
        btn: ['确定','取消'] //按钮
    }, function(){
        $.ajax({
            type: "POST",
            url: ROOT_PATH+'/permission/dictionaryType/addAndAlterDictionaryTypeJudgement.shtml',
            data: {code:$(':input[name=code]').val()},
            dataType: "json",
            success: function(result){
                if (result.success) {
        $.ajax({
            type: "POST",
            url: ROOT_PATH+'/permission/dictionaryType/addDictionary.shtml',
            data: $("#dictionaryTypeForm").serialize(),
            dataType: "json",
            success: function(result){
                //result = $.parseJSON(result);
                if (result.success){
                    //$.messager.progress('close');	// 如果提交成功则隐藏进度条
                    parent.layer.msg(result.message,{time:1000,icon:1},function () {
                        parent.$('#dictionaryTypeList').datagrid('load');
                        parent.layer.closeAll(); //先得到当前iframe层的索引
                    });
                }else {
                    //$.messager.progress('close');	// 如果提交成功则隐藏进度条
                    parent.layer.msg(result.message,{time:1000,icon:2});
                }
            }
        });
                }
                else {
                    layer.msg('字典类型标识重复', {
                        icon: 2,
                        time: 2000
                    });
                }
            }
        });
    });

});
//参数清空
$('#dictionaryTypeReset').on('click',function () {
    $('#dictionaryTypeForm').form('reset');
});
$.extend($.fn.validatebox.defaults.rules, {
    checkCode : {
        validator: function (value) {
            var checkR=$.ajax({
                async : false,
                cache : false,
                type : 'post',
                url :  ROOT_PATH+'/permission/dictionaryType/addAndAlterDictionaryTypeJudgement.shtml',
                data : {
                    code:value
                }
            }).responseText;
            var dataObj=$.parseJSON(checkR);//转换为json对象
            var flag=dataObj.success==true;
            if(!flag){
                $('#code_err').css('display','block');
            }else {
                $('#code_err').css('display','none');
            }
            return flag;
        },
        message: '当前标识已存在！'
    }
});